package com.ocean.everyday.d004_findingtheusersactiveminutes;

import java.util.*;

/**
 * https://leetcode.cn/problems/finding-the-users-active-minutes/
 * <p>
 * 查找用户活跃分钟数
 */
public class FindingTheUsersActiveMinutes2 {
    public static void main(String[] args) {
        int[][] nums = {{0, 5}, {1, 2}, {0, 2}, {0, 5}, {1, 3}};
        FindingTheUsersActiveMinutes2 finding = new FindingTheUsersActiveMinutes2();
        int[] res = finding.findingUsersActiveMinutes(nums, 5);
        System.out.println(Arrays.toString(res));
        int[][] nums2 = {{1, 1}, {2, 2}, {2, 3}};
        res = finding.findingUsersActiveMinutes(nums2, 4);
        System.out.println(Arrays.toString(res));
    }

    public int[] findingUsersActiveMinutes(int[][] logs, int k) {
        Map<Integer, Set<Integer>> map = new HashMap<>();
        // 统计每个id的次数
        for (int[] log : logs) {
            int id = log[0];
            int time = log[1];
            map.putIfAbsent(id, new HashSet<>());
            map.get(id).add(time);
        }
        int[] res = new int[k];
        for (Set<Integer> value : map.values()) {
            int count = value.size();
            // 一个用户的次数
            res[count - 1]++; // 下标是次数 值是用户的数量
        }
        return res;
    }
}
